//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.Contracts;

namespace OpenLS.Core
{
    public  class ObservableStack<T>: Stack<T>, INotifyCollectionChanged
    {
        public new void Push(T item)
        {
            base.Push(item);
            if (CollectionChanged != null)
#if !SILVERLIGHT
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
#else
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item,Count));
#endif
        }
        public new T Pop( )
        {
            Contract.Requires(this.Count > 0);
            T result = base.Pop(); 
            if (CollectionChanged != null)
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, result, Count));
            return result;
        }

        public new void Clear()
        {
            base.Clear();
            if (CollectionChanged != null)
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
        #region INotifyCollectionChanged Members

        public event NotifyCollectionChangedEventHandler CollectionChanged;

        #endregion
    }
}
